package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.constant.CustomEvent;
import com.qire.common.constant.Navigation;
import com.qire.common.support.base.EventController;
import com.qire.common.utils.NoticeEventBus;
import com.qire.manhua.activity.BulletScreenDialogActivity;
import com.qire.manhua.activity.helper.LoginRouter;
import com.qire.manhua.model.viewModel.impl.BulletScreenDialogViewModel;

import androidx.annotation.NonNull;

public class BulletScreenDialogController extends EventController<BulletScreenDialogActivity> {

    private BulletScreenDialogViewModel viewModel;

    public BulletScreenDialogController(@NonNull BulletScreenDialogActivity activity) {
        super(activity);
    }

    @Override
    protected void bindView() {
        owner.viewDataBinder().setBulletScreenDialogController(this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(BulletScreenDialogViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /**************************************************************************************************************/

    /**
     * 点击空白处取消单击事件
     * @param view
     */
    public void closeOnClick(View view) {
        owner.onBackPressed();
        notifyResultsToParent(false);
    }

    /**
     * 发送按钮单击事件
     * @param view
     */
    public void sendBtnOnClick(View view) {
        if(!LoginRouter.ROUTER.checkLoginRouteIfNeed()) {
            notifyResultsToParent(true);
        }
    }

    public void notifyResultsToParent(boolean isSend) {
        owner.hideKeyBoard();
        if(isSend) {
            NoticeEventBus.NOTICE.sendEvent(CustomEvent.BULLET_SCREEN_EDIT_SEND, viewModel.bulletScreenInfo());
        } else {
            NoticeEventBus.NOTICE.sendEvent(CustomEvent.BULLET_SCREEN_EDIT_CANCEL, viewModel.bulletScreenInfo());
        }

        owner.onBackPressed();
    }

    public void openSetTextAttrPanelOnClick(View view) {
        owner.hideKeyBoard();
        viewModel.setShowTextAttrSetPanel(true);
    }

    public void purchaseMemberBtnOnClick(View view) {
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.BuyMembershipPage).navigation();
    }

    public void contentTextOnClick(View view) {
        viewModel.setShowTextAttrSetPanel(false);
    }

    public void colorSelectorRadioOnClick(View view) {
        String colorTag = (String) view.getTag();
        viewModel.setFontColorTag(colorTag);
    }

}
